<?php
/**
 * Created by PhpStorm.
 * User: zhou
 * Date: 2019/4/15
 * Time: 上午11:13
 */

namespace App\Http\Controllers\Api\Hotel;


use App\Http\Controllers\ApiController;
use App\Models\HotelGoods;
use Illuminate\Http\Request;

class HotelGoodsController extends ApiController
{
    /**酒店商品列表
     * @param Request $request
     * @return mixed
     * @throws \ErrorException
     */
    public function hotel_goods_list(Request $request)
    {
       $post = $request -> all();
       if($post['hotel_id'] && isset($post['is_on_sale'])){
           switch ($post['is_on_sale']){
               case 0:
                   $list = HotelGoods::off_sale_goods($post['hotel_id']);
                   break;
               case 1:
                   $list = HotelGoods::on_sale_goods($post['hotel_id']);
                   break;
               default:
                   $list = HotelGoods::on_sale_goods($post['hotel_id']);
                   break;
           }
       }else{
           $list =  HotelGoods::hotel_goods_list($request->all());
       }

       return self::response($list);
    }

    /**更新酒店库存
     * @param Request $request
     * @return mixed
     * @throws \ErrorException
     */
    public function update_stock(Request $request)
    {
        if(!HotelGoods::update_stock($request->all()['data'])){
            return self::response(null,self::ERROR_CODE,HotelGoods::$error);
        }
        return self::response(null,self::SUC_CODE,'更新酒店库存成功');
    }

    /**酒店绑定的商品删除
     * @param Request $request
     * @return mixed
     * @throws \ErrorException
     */
    public function delete_goods(Request $request)
    {
        if(!HotelGoods::delete_hotel_goods($request->all())){
            return self::response(null,self::ERROR_CODE,HotelGoods::$error);
        }
        return self::response(null,self::SUC_CODE,'删除商品成功');
    }

    /**调整酒店下的商品列表的库存
     * @param Request $request
     * @return mixed
     * @throws \ErrorException
     */
    public function update_stock_specially(Request $request)
    {
        if(!HotelGoods::update_hotel_goods_stock($request->all())){
            return self::response(null,self::ERROR_CODE,'调整库存失败');
        }
        return self::response(null,self::SUC_CODE,'调整库存成功');
    }

}